package cn.sz.hy.handler.top;

import java.awt.TextField;
import java.util.List;

import org.eclipse.swt.widgets.Combo;

import cn.sz.hy.common.Globel;
import cn.sz.hy.event.top.StrategySelectEvevt;
import cn.sz.hy.handler.Handler;
import cn.sz.hy.logic.strategy.StrategyFactory;
import cn.sz.hy.logic.strategy.impl.XlsStrategy;
import cn.sz.hy.logic.strategy.vo.TableVo;

public class StrategySelectHandler implements Handler<StrategySelectEvevt> {
	private TextField pathText1;
	private TextField pathText2;

	public StrategySelectHandler(TextField pathText1, TextField pathText2) {
		super();
		this.pathText1 = pathText1;
		this.pathText2 = pathText2;
	}

	@Override
	public void execute(StrategySelectEvevt event) {
		insertData(Globel.MAIN,pathText1.getText());
		insertData(Globel.BACKUP,pathText2.getText());
	}

	private void insertData(int type, String path) {
		Combo executeList = (Combo) eBus.getComponent(Globel.EXECUTE_LIST_ID);
		XlsStrategy xs = StrategyFactory
				.getStrategy(executeList.getSelectionIndex());
		List<TableVo> tempList = xs.loadHeader(path);
		if (tempList != null) {
		    eBus.addTableVo(type, tempList.get(0));
		}
	}

}
